package com.kx.center.util;

import com.kx.center.common.MyQueue;
import com.kx.center.entity.MsgSend;
import com.kx.center.service.CallBackInterface;

/**
 * @description 发送jpush通知的线程
 * @version 1.0
 * @author Scott 
 * @date 2016年1月7日 下午5:44:31
 */
public class SendJpushThread implements Runnable{
	private MyQueue<MsgSend> myqueue ;
	private CallBackInterface callback;
	
	public  SendJpushThread(MyQueue<MsgSend> myqueue,CallBackInterface callback) {
		this.myqueue = myqueue;
		this.callback = callback;
	}
	
	@Override
	public void run() {
		// 遍历队列 发送jpush消息
		int successNum = 0;
		int noticeId = 0;
		while(!myqueue.isEmpty()){
			MsgSend msgSend = myqueue.poll();
			noticeId = msgSend.getNoticeMsgId();
			String alias = msgSend.getAppAccountId()+msgSend.getAppAccountUserId();
			String title = msgSend.getTitle();
			if(JpushUtil.noticeMsgPush(alias, title, msgSend)){
				++ successNum ;
			}
			
		}
		//更新发送成功人数
		callback.updateSendNum(noticeId, successNum);
	}

}
